package com.weilai.dao;

import com.weilai.domain.Categories;
import com.weilai.domain.Comments;
import com.weilai.domain.Posts;
import com.weilai.domain.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper

public interface AdminDao {
    @Select("SELECT * FROM categories WHERE id=#{id}")
    public Categories selectCategoryById(int id);

    @Select("SELECT * FROM categories ")
    public List<Categories> selectAllCategory();

    @Update("UPDATE categories SET name=#{name},description=#{description} WHERE id=#{id}")
    public void manageCategory(Categories category);

    @Insert("INSERT INTO categories values (null,#{name},#{description},#{createdBy})")
    public void insertCategory(Categories category);

    @Delete("DELETE FROM categories WHERE id = #{id}")
    public void deleteCategoryById(int id);

    @Select("SELECT * FROM posts WHERE status='审核中'")
    public List<Posts> selectPostsUnderChecking();

    @Update("UPDATE posts SET status='已发布' WHERE id=#{id}")
    public void approvePost(int id);

    //禁言用户
    @Update("UPDATE users SET status='禁言' WHERE  id=#{id}")
    public void muteUser(int id);

    //解除禁言
    @Update("UPDATE users SET status='正常' WHERE  id=#{id}")
    public void unMuteUser(int id);

    //查询审核中的评论
    @Select("SELECT * FROM comments WHERE status='审核中'")
    public List<Comments> commentsUnderChecking();

    //驳回评论
    @Update("UPDATE comments SET status='未通过' WHERE id=#{id}")
    public void rejectComment(int id);

    //评论成功
    @Update("UPDATE comments SET status='已发布' WHERE id=#{id}")
    public void approveComment(int id);

    //
    @Select("SELECT * FROM comments WHERE id=#{id}")
    public Comments selectCommentById(int id);

    //模糊查询用户
    @Select("SELECT *FROM users WHERE username like contact('%',#{keyWord},'%') or email like contact('%',#{keyWord},'%')")
    public User fuzzyQueryUser(String keyWord);
}
